//
//  BaseDataVC.m
//  MZJ
//
//  Created by XDD on 16/6/3.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "BaseDataVC.h"
#import "BaseDataCell.h"

@interface BaseDataVC () <UITableViewDelegate,UITableViewDataSource> {
    NSArray *nameArr;
}

@property (nonatomic, strong) UITableView *baseData_TabelView;


@end

@implementation BaseDataVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.topBar.backgroundColor = [UIColor colorWithRed:253/255.0 green:179/255.0 blue:10/255.0 alpha:1];
    self.titleLabel.text = @"基本资料";
    self.view.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    [self.backButton setTitle:@"" forState:UIControlStateNormal];
    
    self.baseData_TabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 55, kWidth, kHeight - 55)];
    self.baseData_TabelView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    self.baseData_TabelView.delegate = self;
    self.baseData_TabelView.dataSource = self;
    [self.baseData_TabelView registerNib:[UINib nibWithNibName:@"BaseDataCell" bundle:nil] forCellReuseIdentifier:@"baseDataCell"];
    self.baseData_TabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.baseData_TabelView];
    
    nameArr = @[@"头像",@"昵称",@"性别",@"年龄",@"真实姓名",@"身份证号码",@"联系方式",@"地址",@"愿意成为志愿者"];
}

//点击返回键
- (void)clickedBackButton:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
}

#pragma mark -- tableview－delegate、dataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return nameArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 80;
    }
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifier = @"baseDataCell";
    BaseDataCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (!cell) {
        
        cell = [[BaseDataCell alloc] initWithFrame:CGRectZero];
    }
    cell.headImageView.hidden = YES;
    cell.nameLabel.text = nameArr[indexPath.row];
    cell.chooseImageView.hidden = YES;
    cell.sexLabel.hidden = YES;
    if (indexPath.row == 0) {
        cell.detailLabel.hidden = YES;
        cell.headImageView.hidden = NO;
        [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:[DataModel object].userDetail[@"uheadimg"]]
                              placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    }
    if (indexPath.row == 1) {
        cell.detailLabel.text = [DataModel object].userDetail[@"unickname"];
    }
    if (indexPath.row == 2) {
        cell.chooseImageView.hidden = NO;
        cell.sexLabel.hidden = NO;
        cell.detailLabel.hidden = YES;
        NSString *sex_Str = [NSString stringWithFormat:@"%@",[DataModel object].userDetail[@"usex"]];
        if ([sex_Str intValue] == 0) {
            cell.detailLabel.hidden = NO;
            cell.sexLabel.hidden = YES;
            cell.chooseImageView.hidden = YES;
            cell.detailLabel.text = @"未设置";
        } else {
            if ([sex_Str intValue] == 1) {
//                cell.chooseImageView.backgroundColor = [UIColor blackColor];
//                cell.chooseImageView.image = [UIImage imageNamed:@"Checked-YES_img@2x"];
                cell.sexLabel.text = @"男";
            } else {
//                cell.chooseImageView.backgroundColor = [UIColor purpleColor];
//                cell.chooseImageView.image = [UIImage imageNamed:@"Checked-YES_img@2x"];
                cell.sexLabel.text = @"女";
            }
        }
    }
    if (indexPath.row == 3) {
        cell.detailLabel.text = [DataModel object].userDetail[@"uage"];
    }
    if (indexPath.row == 4) {
        NSString *ucompellation_Str = [NSString stringWithFormat:@"%@",[DataModel object].userDetail[@"ucompellation"]];
        if ([ucompellation_Str isEqualToString:@"<null>"]) {
            cell.detailLabel.text = @"未设置";
        } else {
            cell.detailLabel.text = [DataModel object].userDetail[@"ucompellation"];
        }
    }
    if (indexPath.row == 5) {
        NSString *ucard_Str = [NSString stringWithFormat:@"%@",[DataModel object].userDetail[@"ucard"]];
        if (ucard_Str.length < 16) {
            cell.detailLabel.text = @"未设置";
        } else {
            cell.detailLabel.text = [DataModel object].userDetail[@"ucard"];
        }
    }
    if (indexPath.row == 6) {
        cell.detailLabel.text = [DataModel object].userDetail[@"umobile"];
    }
    if (indexPath.row == 7) {
        NSString *address_Str = [NSString stringWithFormat:@"%@",[DataModel object].userDetail[@"uaddress"]];
        if ([address_Str isEqualToString:@"<null>"]) {
            cell.detailLabel.text = @"未设置";
        } else {
            cell.detailLabel.text = [DataModel object].userDetail[@"uaddress"];
        }
    }
    if (indexPath.row == 8) {
        cell.chooseImageView.frame = CGRectMake(130, 18, 14, 14);
        cell.sexLabel.frame = CGRectMake(155, 16, 20, 20);
        cell.chooseImageView.hidden = NO;
        cell.sexLabel.hidden = NO;
        cell.detailLabel.hidden = YES;
        if ([[DataModel object].userDetail[@"utype"] intValue] == 0) {
//            cell.chooseImageView.backgroundColor = [UIColor blackColor];
//            cell.chooseImageView.image = [UIImage imageNamed:@"Checked-NO_img@2x"];
            cell.sexLabel.text = @"否";
        } else {
//            cell.chooseImageView.backgroundColor = [UIColor purpleColor];
//            cell.chooseImageView.image = [UIImage imageNamed:@"Checked-YES_img@2x"];
            cell.sexLabel.text = @"是";
        }
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
